package com.synnex.mobile.servier.core.calendar.service.impl;

import com.synnex.mobile.generic.core.util.ObjectUtil;
import com.synnex.mobile.servier.core.calendar.bo.CalendarBo;
import com.synnex.mobile.servier.core.calendar.dao.CalendarDao;
import com.synnex.mobile.servier.core.calendar.dto.Calendar;
import com.synnex.mobile.servier.core.calendar.service.CalendarService;
import com.synnex.mobile.servier.core.service.impl.AbstractServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * Date: 13-8-6
 * To change this template use File | Settings | File Templates.
 */
@Transactional
public class CalendarServiceImpl extends AbstractServiceImpl implements CalendarService {

    private CalendarDao calendarDao;

    public void setCalendarDao(CalendarDao calendarDao) {
        this.calendarDao = calendarDao;
    }


    public List<CalendarBo> listCalendar(Date date) {
       List<Calendar> data = calendarDao.listCalendar(date);
        return CalendarBo.createInstance(data);
    }

    public void addCalendar(CalendarBo calendar) {

        Calendar data = ObjectUtil.copyProperties(calendar,Calendar.class);
        data.setEntryDate(new Date());
        calendarDao.addCalendar(data);
    }

    public void deleteCalendar(Integer id) {
       calendarDao.deleteCalendar(id);
    }

    public CalendarBo getCalendarBoById(Integer id) {
        Calendar calendar = calendarDao.getCalendarById(id);
        return CalendarBo.createInstance(calendar);
    }

    public void editCalendar(CalendarBo calendarBo) {
        Calendar data = ObjectUtil.copyProperties(calendarBo,Calendar.class);
        data.setUpdateDate(new Date());
        calendarDao.editCalendar(data);
    }
}
